import cv2 as cv

# cap = cv.VideoCapture(0)
cap = cv.VideoCapture('../rw222rgjk/opencv/img/光厂_24362603_山区行驶行车记录仪.mp4')
# frame per second 每秒帧数
fps = cap.get(cv.CAP_PROP_FPS)
print(fps)

# 使用循环显示画面
while 1:
    # 读取一帧
    ret, frame = cap.read()
    # ret 返回值，frame 读取的帧
    if not ret:
        print('读取失败')
        break
    # 显示画面
    cv.imshow('frame', frame)
    # 等待时间，单位毫秒
    # 500 / fps 表示一帧的等待时间
    key = cv.waitKey(int(500 / fps))
    # 按下ESC键退出
    if key == 13:
        print('回车')
        break
    elif key == 27:
        print('ESC')
        break
    elif key==ord('q'):
        print('Q')
        break
# 释放资源
cap.release()
# 关闭窗口
cv.destroyAllWindows()